#include <amxmodx>
#include <items>
#include <engine>

#define MAX_JUMPS	15

new PLUGIN_NAME[] 	= "UM Item: Multi Jump"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.1"

new bool:g_MultiJump[33]
new bool:g_DoJump[33]
new g_JumpNum[33]
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("Multi Jump", "Jump in the air", 2800)
}

public client_connect(id) {
	g_MultiJump[id] = false
}

public Enable_Item(id) {
	g_MultiJump[id] = true
}

public Disable_Item(id) {
	g_MultiJump[id] = false
}

public client_PreThink(id)
{
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_MultiJump[id]) {
		return PLUGIN_CONTINUE
	}
	
	new Button = get_user_button(id)
	new oButton = get_user_oldbutton(id)
	if((Button & IN_JUMP) && !(get_entity_flags(id) & FL_ONGROUND) && !(oButton & IN_JUMP))
	{
		if(g_JumpNum[id] < MAX_JUMPS)
		{
			g_DoJump[id] = true
			g_JumpNum[id] += 1
			return PLUGIN_CONTINUE
		}
	}
	if((Button & IN_JUMP) && (get_entity_flags(id) & FL_ONGROUND))
	{
		g_JumpNum[id] = 0
		return PLUGIN_CONTINUE
	}
	return PLUGIN_CONTINUE
}
		
public client_PostThink(id)
{
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}

	if(g_DoJump[id])
	{
		new Float:flVelocity[3]	
		entity_get_vector(id, EV_VEC_velocity, flVelocity)
		flVelocity[2] = random_float(265.0, 285.0)
		entity_set_vector(id, EV_VEC_velocity, flVelocity)
		g_DoJump[id] = false

		return PLUGIN_CONTINUE
	}
	return PLUGIN_CONTINUE
}
